package com.hermes.biz.manager.usermodelextraImpl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.hermes.biz.common.model.usermodelextra.UserModelExtraDAO;
import com.hermes.biz.common.model.usermodelextra.UserModelExtraDO;
import com.hermes.biz.common.util.string.StringUtil;
import com.hermes.biz.manager.usermodelextra.UserModelExtraManager;

public class UserModelExtraManagerImpl implements UserModelExtraManager{
	
	private UserModelExtraDAO userModelExtraDAO;

	public UserModelExtraDAO getUserModelExtraDAO() {
		return userModelExtraDAO;
	}

	public void setUserModelExtraDAO(UserModelExtraDAO userModelExtraDAO) {
		this.userModelExtraDAO = userModelExtraDAO;
	}

	public long getFansCount(long userId) {
		long fansCount = 0;
		UserModelExtraDO userModelExtraDO =  this.userModelExtraDAO.getFansCount(userId);
		if(userModelExtraDO!=null){
			fansCount = userModelExtraDO.getFansCount();			
		}else{
			return 0;
		}
		return fansCount;
	}

	public long getEyeonCount(long userId) {
		long eyeonCount = 0;
		UserModelExtraDO userModelExtraDO =  this.userModelExtraDAO.getEyeonCount(userId);
		if(userModelExtraDO!=null){
			eyeonCount = userModelExtraDO.getEyeonCount();
		}else{
			return 0;
		}
		return eyeonCount;
	}

	public Set<String> getFansIdsMap(long userId) {	
		Set<String> fansIds = new HashSet<String>();
		UserModelExtraDO userModelExtraDO =  this.userModelExtraDAO.getFansIds(userId);
		if(userModelExtraDO!=null){			
			String[] str_fansIds = userModelExtraDO.getFansIds().split(",");
			fansIds = new HashSet<String>(Arrays.asList(str_fansIds));			
		}else{
			return null;
		}
		return fansIds;
	}

	@SuppressWarnings("unchecked")
	public Set<String> getEyeonIdsMap(long userId) {
		Set<String> eyeonIds = new HashSet<String>();
		UserModelExtraDO userModelExtraDO =  this.userModelExtraDAO.getEyeonCount(userId);
		if(userModelExtraDO!=null){
			 eyeonIds = (HashSet<String>) Arrays.asList(userModelExtraDO.getEyeonIds().split(","));
		}else{
			return null;
		}
		return eyeonIds;
	}

	public List<Long> getUserFansList(long userId) {
		
		List<Long> fansIds = new ArrayList<Long>();
		
		UserModelExtraDO userModelExtraDO =  this.userModelExtraDAO.getFansIds(userId);
		if(userModelExtraDO!=null){			
			String[] str_fansIds = userModelExtraDO.getFansIds().split(",");
			for(String idStr:str_fansIds){
				if(StringUtil.isNumOnly(idStr)){
					long userIdNum = Long.parseLong(idStr);
					fansIds.add(userIdNum);
				}
			}
		}else{
			return new ArrayList<Long>();
		}
		return fansIds;
	}

	public boolean followSingleUserById(long userId, long followUserIds) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean removeConcernUserByUserId(long userId, long removedId) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean followBatchUsersByUserIdList(long userId, List<Long> userIds) {
		// TODO Auto-generated method stub
		return false;
	}

}
